<?php

namespace Home\Controller; 
use Think\Controller;

class PublicUserController extends  BaseUserController {
    //【我的晒单】晒单记录
    public function order_share_mylist_datalist(){
        
        
        $type=intval($_REQUEST['type']);
        $page=intval($_REQUEST['page']);
        
        
        $pageSize = 10;//每页显示的记录数
        $first_Record = ($page-1)*$pageSize;//起始值
        
        $user_id=$_SESSION["user_id"];
        if(!$user_id){
            echo "未登录或登录超时，请重新登录！";
            exit;
        }
         
          
        $users_income = M('users_income');

        $data_list = $users_income->join('INNER JOIN js_users as u ON js_users_income.customer_user_id = u.user_id' )
           -> field('js_users_income.add_time,u.nickname,js_users_income.in_money,js_users_income.level_id,js_users_income.order_money,js_users_income.order_sn ')
           -> where(array('js_users_income.user_id'=>$user_id))
           ->order('id desc')
           ->limit($first_Record,$pageSize)->select();
        
        //echo $users_income->getlastSql();
        
        $this->assign("data_list",$data_list);
        $this->display("mydist_incomelist");
        exit;
    }
    
    
	//检测下单绑定手机时候的验证码是否正确
    public function user_bdmobile_checkmcode()
    {
        
    	$is_confirm_complete = I('request.is_confirm_complete',0,'intval');
    	
    	if( !empty($is_confirm_complete) ){
    		
    		$request_mcode=I("bdmobile_code",'','trim');
    		$request_mobile=I("bdmobile_mobile",'','trim');
    		
    		$mobile_code=empty($_SESSION['mobile_code'])?"":$_SESSION['mobile_code'];
    		$mobile=empty($_SESSION['mobile'])?"":$_SESSION['mobile'];
    		
    		if(!$request_mobile || ($mobile != $request_mobile)){
    			$this->error("手机号码与接收验证码的手机号码不匹配，请检查");exit;
    		}
    		
    		//如果没有输入验证码， 或者输入的验证码和发出去的验证码不一致
    		if(!$request_mcode || ($request_mcode!= $mobile_code))
    		{
    			$this->error("验证码输入错误，请检查一下是否和短信内容一致");exit;
    		}
    		
    		//判断密码
    		$password_1=I("bdmobile_pass1",'','trim');
    		$password_2=I("bdmobile_pass2",'','trim');
    		
    		if(empty($password_1)){
    			$this->error("请输入登录密码");exit;
    		}
//     		if(empty($password_2)){
//     			$this->error("请确认登录密码");
//     		}
//     		if($password_2 != $password_1){
//     			$this->error("2次密码输入不一致，请重新输入");
//     		}
    		
    		
    		//获取当前用户ID
    		$user_id=empty($_SESSION['user_id'])?0:$_SESSION['user_id'];
    		if( $user_id <= 0 )
    		{
    			$this->error("登录超时，请重新登录试试");exit;
    		}
    		    	
    		
    		//如果当前用户已有手机号码，则返回成功
    		$user_entity=M('users')->where(array('user_id'=>$user_id))->field('password,user_id,ec_salt')->find();
    		
    		$ec_salt = trim($user_entity['ec_salt']);    		
    		$_password = md5(md5($password_1).$ec_salt);
    		
    		if( $_password !== $user_entity['password'] ){
    			$this->error("登录密码输入错误,请重新输入!");exit;
    		}
    		
    		//修改手机和用户名
    		$data['user_name']=$request_mobile;
    		$data['mobile_phone']=$request_mobile;    	
    		M('users')->where(array('user_id'=>$user_id))->save($data);
    		
    		
    		unset($_SESSION['user_id']);
    		
    		$this->success("1");
    		
    	}else{
    		
    		$request_mcode=empty($_REQUEST['mcode'])?"":$_REQUEST['mcode'];
    		$request_mobile=empty($_REQUEST['mobile'])?"":$_REQUEST['mobile'];
    		
    		$mobile_code=empty($_SESSION['mobile_code'])?"":$_SESSION['mobile_code'];
    		$mobile=empty($_SESSION['mobile'])?"":$_SESSION['mobile'];
    		
    		if(!$request_mobile || ($mobile != $request_mobile)){
    			$this->error("手机号码与接收验证码的手机号码不匹配，请检查");
    		}
    		
    		//如果没有输入验证码， 或者输入的验证码和发出去的验证码不一致
    		if(!$request_mcode || ($request_mcode!= $mobile_code))
    		{
    			$this->error("验证码输入错误，请检查一下是否和短信内容一致");
    		}
    		
    		//校验成功
    		$this->success("");
    		
    	}
  
        exit;
        
    }
    
}

